package com.pic.mgt.config;

import java.io.IOException;

import javax.xml.stream.XMLStreamException;

import org.apache.axiom.om.OMElement;
import org.xml.sax.SAXException;

import com.pic.mgt.utils.XMLProcessUtils;

public abstract class XMLConfig {
	protected XMLConfig() throws ParseXMLException {
		loadConfig();
	}
	
	protected OMElement parseXMLConfigFile(String appointedHaishinConfigFile,
								   String appointedHaishinConfigSchemaFile)
		throws XMLStreamException, SAXException, IOException, Exception
											 {
		OMElement rootElement;		
		// 剖析並驗證(符合Schema)XML設定檔
		// throws XMLStreamException, SAXException, IOException, Exception
		rootElement =
			XMLProcessUtils.parseXMLFile(appointedHaishinConfigFile,
										 appointedHaishinConfigSchemaFile);
		return rootElement;
	}
	
	/**
	 * 當 XMLConfig 物件被生成時,loadConfig()就會被呼叫。
	 * 因此可在方法內開始讀取 XML設定檔的內容。
	 * @throws ParseXMLException
	 */
	protected abstract void loadConfig() throws ParseXMLException;

	@Override
	protected Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException();
	}
}
